using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace Acms.SqlDal
{
    public class ExceptionLogDal : Base
    {
        public ExceptionLogDal() : base() { }

        public enum Fields
        {
            Id,
            ServerName,
            ApplicationRoot,
            Url,
            RawUrl,
            PostId,
            SiteId,
            ExceptionType,
            ExceptionMessage,
            InnerExceptionType,
            InnerExceptionMessage,
            Source,
            StackTrace,
            Created
        }

        protected override void ReadRecord(Hashtable table, SqlDataReader reader)
        {
            GetReaderValue<int>(Fields.Id, reader, table);
            GetReaderValue<string>(Fields.ServerName, reader, table);
            GetReaderValue<string>(Fields.ApplicationRoot, reader, table);
            GetReaderValue<string>(Fields.Url, reader, table);
            GetReaderValue<string>(Fields.RawUrl, reader, table);
            GetReaderValue<int>(Fields.PostId, reader, table);
            GetReaderValue<int>(Fields.SiteId, reader, table);
            GetReaderValue<string>(Fields.ExceptionType, reader, table);
            GetReaderValue<string>(Fields.ExceptionMessage, reader, table);
            GetReaderValue<string>(Fields.InnerExceptionType, reader, table);
            GetReaderValue<string>(Fields.InnerExceptionMessage, reader, table);
            GetReaderValue<string>(Fields.Source, reader, table);
            GetReaderValue<string>(Fields.StackTrace, reader, table);
            GetReaderValue<DateTime>(Fields.Created, reader, table);
        }

        public void Update(string serverName, string applicationRoot, string url, string rawUrl, int postId, int siteId, string exceptionType, string exceptionMessage, string innerExceptionType, string innerExceptionMessage, string source, string stackTrace, DateTime created, ref int idOut)
        {
            SqlCommand cmd = CreateCommand("Put");
            AddInputParameter(cmd, "ServerName", serverName, SqlDbType.VarChar, 50);
            AddInputParameter(cmd, "ApplicationRoot", applicationRoot, SqlDbType.VarChar, 50);
            AddInputParameter(cmd, "Url", url, SqlDbType.VarChar, 255);
            AddInputParameter(cmd, "RawUrl", rawUrl, SqlDbType.VarChar, 255);
            AddInputParameter(cmd, "PostId", postId, SqlDbType.VarChar, 255);
            AddInputParameter(cmd, "SiteId", siteId, SqlDbType.VarChar, 255);
            AddInputParameter(cmd, "ExceptionType", exceptionType, SqlDbType.VarChar, 255);
            AddInputParameter(cmd, "ExceptionMessage", exceptionMessage, SqlDbType.VarChar, 2000);
            AddInputParameter(cmd, "InnerExceptionType", innerExceptionType, SqlDbType.VarChar, 255);
            AddInputParameter(cmd, "InnerExceptionMessage", innerExceptionMessage, SqlDbType.VarChar, 2000);
            AddInputParameter(cmd, "Source", source, SqlDbType.VarChar, 100);
            AddInputParameter(cmd, "StackTrace", stackTrace, SqlDbType.VarChar, 2000);
            AddInputParameter(cmd, "Created", created, SqlDbType.DateTime);
            AddOutputParameter(cmd, "IdOut", SqlDbType.Int);

            ExecuteCommand(cmd);

            idOut = GetOutputValue<int>(cmd, "IdOut");
        }
    }
}
